{% extends "personal_center/base.html" %}
<!--固定资产付款创建页-->
{% block page_link %}
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <link rel="stylesheet" href="../../static/public_file/css/DepartmentSelection.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        tr {
            height: 37px;
        }
        th {
            text-align: center;
        }
        tbody td {
            overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
        }
        td:first-child, th:first-child {
            position: sticky;left: 0;z-index: 1;
        }
        thead tr th {
            position: sticky;top: 0;background-color: #E8E8E8;
        }
        th:first-child {
            z-index: 2;
        }
        #tb_1 tr:hover {
            background: #cfcfcf;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 4px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
        .search {
            width: 300px;display: flex;float: right;margin: 10px 0;margin-right: 1%;
        }
        .search input {
            vertical-align: middle;float: left;height: 30px;width: 230px;outline: none;border: 1px solid #0070c1;box-sizing: border-box;border-bottom-left-radius: 3px;border-top-left-radius: 3px;
        }
        .search button {
            float: right;flex: 1;height: 30px;width: 70px;line-height: 30px;background-color: #0070c1;color: white;border-style: none;outline: none;border-bottom-right-radius: 3px;border-top-right-radius: 3px;
        }
        .search button i {
            font-style: normal;
        }
        .search button:hover {
            font-size: 16px;
        }
        .check_anniu {
            cursor: pointer;
        }
        .association {
            display: inline-block;width: 120px;vertical-align: top;height: 40px;cursor: pointer;text-align: center;line-height: 40px;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <span> 新增申请</span>
            </a>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="summit_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="ExportCar()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;overflow: auto;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 95%;height: auto;display: inline-block;vertical-align: center;margin-left: 2.5%;">
                <div style="width: 100%">
                    <table style="width: 100%;margin-top: 1%;">
                        <tr style="width: 100%;">
                            <td colspan="4" style="height: 40px;text-align: center;border: #cfcfcf solid 0.5px;"><h3>付款流程申请</h3></td>
                        </tr>
                        <tr>
                            <td colspan="4" style="border: #cfcfcf solid 0.5px;width: 95%;margin-left: 2.5%;margin-top: 1%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;">
                                基本信息
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 37px;line-height: 37px;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">申请人</p>
                            </td>
                            <td id="applicat"
                                style="width: 35%;height: 37px;line-height: 37px;padding-left: 1%;border: #cfcfcf solid 0.5px;">
                                {{ realname }}
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">所属科室</p>
                            </td>
                            <td id="company"
                                style="width: 35%;height: 37px;line-height: 37px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ department }}</td>
                        </tr>
                        <tr>
                            <td colspan="4" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;border-left: #cfcfcf solid 0.5px;">申请详情</td>
                        </tr>

                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">付款事由</p>
                            </td>
                            <td id="pay_reason" style="width: 35%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;padding-left: 0.5%;outline: none;" contenteditable="true">

                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">经费来源</p>
                            </td>
                            <td id="" style="width: 35%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: left;padding-left: 0.5%;outline: none;">
                                <select name="" id="source_funds" style="width: 100%;height: 100%;border: none;outline: none;">
                                    <option value="0">请选择经费来源</option>
                                    <option value="1">自有经费</option>
                                    <option value="2">学科经费</option>
                                    <option value="3">科研经费</option>
                                    <option value="4">财政拨款</option>
                                    <option value="5">贴息贷款</option>
                                    <option value="6">专项债券</option>
                                    <option value="7">工会经费</option>
                                </select>
                            </td>

                        </tr>
                        <tr style="width: 100%;">
                            <td style="border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;width: 15%;"><p style="width: 100px;float: right;text-align-last: justify;">收款单位</p></td>
                            <td style="text-align: left;padding-left: 0.5%;width: 35%;outline: none;height: 37px;line-height: 37px;" id="payee" contenteditable="true">{{ obj.payee }}</td>
                            <td style="border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;width: 15%;"><p style="width: 100px;float: right;text-align-last: justify;">收款账号</p></td>
                            <td style="border-right: #cfcfcf solid 0.5px; text-align: left;padding-left: 0.5%;width: 35%;outline: none;height: 37px;line-height: 37px;" id="payee_account" contenteditable="true">{{ obj.payee_account }}</td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">总金额(元)</p>
                            </td>
                            <td style="width: 35%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;">
                                <input type="text" id="total_money" style="width: 100%;height: 37px;line-height: 37px;padding-left: 1%;border:none;outline: none;" onblur="change_daxie()">
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">大写</p>
                            </td>
                            <td style="width: 35%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;padding-left: 0.5%;" id="daxie">
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">开户行</p>
                            </td>
                            <td id="BankDeposit" style="width: 35%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;outline: none;padding-left: 0.5%;" contenteditable="true">
                            </td>
                            <td style="border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;width: 15%;"><p style="width: 100px;float: right;text-align-last: justify;">付款类型</p></td>
                            <td style="border-right: #cfcfcf solid 0.5px; text-align: left;padding-left: 0.5%;width: 35%;outline: none;height: 37px;line-height: 37px;">
                                <select name="" id="pay_type_select" style="width: 100%;height: 100%;border: none;outline: none;" onchange="change_pay_type()">
                                    <option value="0">请选择付款类型</option>
                                    <option value="1">合同付款</option>
                                    <option value="2">固定资产/维修维保付款</option>
                                    <option value="3">材料付款</option>
                                    <option value="4">餐补付款</option>
                                    <option value="5">学科经费</option>
                                    <option value="6">科研经费</option>
                                    <option value="7">一般付款</option>
                                    <option value="8">工会经费</option>
                                </select>
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;"><p style="width: 100px;float: right;text-align-last: justify;">接待事前审批</p></td>
                            <td id="PreReception" style="width: 35%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;outline: none;padding-left: 0.5%;color: #cfcfcf;" ondblclick="association_line(this.id)">双击选择流程</td>
                            <td style="border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;width: 15%;"><p style="width: 100px;float: right;text-align-last: justify;">接待清单</p></td>
                            <td id="ReceptionChecklist" style="border: #cfcfcf solid 0.5px; text-align: left;padding-left: 0.5%;width: 35%;outline: none;height: 37px;line-height: 37px;color: #cfcfcf;" ondblclick="association_line(this.id)">双击选择流程</td>
                        </tr>
                        {% if bgs_flag == 'true' %}
                            <tr>
                                <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                    <p style="width: 100px;float: right;text-align-last: justify;">备注</p>
                                </td>
                                <td id="rask" style="width: 35%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;outline: none;padding-left: 0.5%;" contenteditable="true"></td>
                                <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                    <p style="width: 100px;float: right;text-align-last: justify;">分管领导</p>
                                </td>
                                <td style="width: 35%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;outline: none;padding-left: 0.5%;">
                                    <select name="" id="fenguan_leader" style="width: 100%;height: 100%;border: none;outline: none;">
                                        <option value="0">请选择分管领导</option>
                                        {% for leader in leaders_obj %}
                                            <option value="{{ leader.id }}">{{ leader.real_name }}</option>
                                        {% endfor %}
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                    <p style="width: 100px;float: right;text-align-last: justify;">承办科室</p>
                                </td>
                                <td id="demand_office" colspan="3" onclick="show_office_model()" style="width: 85%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;outline: none;padding-left: 0.5%;"></td>
                            </tr>
                        {% else %}
                            <tr>
                                <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                    <p style="width: 100px;float: right;text-align-last: justify;">备注</p>
                                </td>
                                <td id="rask" colspan="3" style="width: 85%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;outline: none;padding-left: 0.5%;" contenteditable="true"></td>
                            </tr>
                        {% endif %}
                        <tr id="expense_category_tr" style="display: none;">
                            <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 37px;line-height: 37px;text-align: right;padding-right: 1%;">
                                <p style="width: 100px;float: right;text-align-last: justify;">费用类别</p>
                            </td>
                            <td colspan="3" style="width: 85%;height: 37px;line-height: 37px;border: #cfcfcf solid 0.5px;outline: none;padding-left: 0.5%;">
                                <select id="expense_category" style="width: 100%;height: 100%;outline: none;border: none;">
                                    <option value="0">请选择费用类别</option>
                                    <option value="1">专利申请费</option>
                                    <option value="2">外出参加学术会议</option>
                                    <option value="3">外出参加技能培训</option>
                                    <option value="4">外出进修学习</option>
                                    <option value="5">教学设备</option>
                                    <option value="6">教授劳务费</option>
                                    <option value="7">教授接待费</option>
                                    <option value="8">版面费</option>
                                    <option value="9">其他</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
                <div style="width: 100%;">
                    <div style="width: 100%;height: 40px;line-height: 40px;background-color: #F5F5F5;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                        <p style="display: inline-block;">上传附件</p>
                        <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                            上传文件
                            <input type="file" name="party_main_body" id="party_main_body"
                                   onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                        </a>
                    </div>
                    <table style="width: 100%;">
                        <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件名称
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件大小
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传时间
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传人员
                            </td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                            </td>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main"></tbody>
                    </table>
                    <table style="width: 100%;">
                        <tr style="width: 100%;">
                            <td colspan="3" style="width: 45%;border: #cccccc solid 1px;border-top: none;color: red;padding-left: 0.5%;">
                                备注：<br>
                                此流程只针对一万元以下付款，一万元以上请走议题流程！<br>
                                公务接待须关联【公务(外宾)接待事前审批】与【公务(外宾)接待清单审批】流程
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div id="selection-office" class="office-shade">
        <div id="office-model">
            <!-- 标题 -->
            <div id="office-title">
                <h5 style="line-height: 40px;width: 15%;margin-left: 1%;display: inline-block;font-size: 14px;">选择科室</h5>
                <span onclick="close_office_models()" style="float: right;line-height: 50px;padding-right: 2%;cursor: pointer;"><i class="iconfont icon-quchu"></i></span>
            </div>
            <hr>
            <div style="width: 55%;height: 350px;vertical-align: top;left: 0;display: inline-block;border-right: #cfcfcf solid 1px;">
                <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;">
                    <input id="search_data1" onkeydown="search_dep()" class="search-input" type="text" placeholder="搜索" autocomplete="off">
                </div>
                <div id="processed" style="width: 100%;height: 300px;overflow: auto;">
                    {% for company in company_list %}
                        <div style="width: 100%;height: 30px;line-height: 30px;font-size: 14px;color: #0b0b0b;">
                            <input class="check_box1" id="{{ company.id }}" type="checkbox" onclick="check_dep_ff('{{ company.name }}', '{{ company.id }}', false)"> {{ company.name }}
                        </div>
                    {% endfor %}
                </div>
            </div>

            <div style="width: 43%;height: 360px;vertical-align: top;left: 0;display: inline-block;">
                <div style="width: 100%;height: 50px;line-height: 50px;padding-left: 2%;font-size: 14px;">
                    已选择科室
                </div>
                <div id="processed_prople" style="width: 100%;height: 265px;overflow: auto;padding-left: 2%;">

                </div>
                <div style="width: 100%;height: 40px;text-align: center;">
                    <button onclick="summit_val()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #1E90FF solid 1px;background: #1E90FF;color: white;width: 80px;letter-spacing: 4px;font-size: 14px;">
                        提交
                    </button>
                    <button onclick="close_office_models()" style="border-radius: 2px;height: 30px;margin-top: 5px;border: #cfcfcf solid 1px;width: 80px;letter-spacing: 4px;margin-left: 15px;font-size: 14px;">
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div id="association" class="office-shade">
        <div id="association-model" style="width: 700px;background: white;left: 50%;top: 50%;position: absolute;transform: translate(-50%, -50%);height: 500px;">
            <div id="association-title" style="width: 100%;height: 40px;border-bottom: #cfcfcf solid 1px;font-size: 14px;cursor: move;">
                <div style="display: inline-block;vertical-align: top;width: 70%;height: 100%;">
                    <div id="SwitchOne" class="association">
                        接待事前审批
                    </div>
                    <div id="SwitchTwo" class="association" style="display: none;">
                        接待清单
                    </div>
                </div>
                <span onclick="close_association()" style="float: right;line-height: 40px;padding-right: 2%;cursor: pointer;vertical-align: top;"><i class="iconfont icon-quchu"></i></span>
            </div>
            <div style="width: 100%;height: 460px;margin: 0;padding: 0;border-collapse: collapse;">
                <div id="approval_reception" style="width: 100%;height: 405px;overflow: auto;border-bottom: #cfcfcf solid 1px;vertical-align: top;">
                    <table style="width: 100%;margin: 0;padding: 0;border-collapse: collapse;">
                        <tr style="width: 100%;">
                            <th style="width: 5%;height: 35px;border: #cfcfcf solid 1px;text-align: center;border-top: none;"></th>
                            <th style="width: 8%;height: 35px;border: #cfcfcf solid 1px;text-align: center;border-top: none;">序号</th>
                            <th style="width: 87%;height: 35px;border: #cfcfcf solid 1px;text-align: center;border-top: none;">申请事由</th>
                        </tr>
                        {% for Bef in BeforehandObj %}
                            <tr style="width: 100%;">
                                <td style="width: 5%;height: 35px;border: #cfcfcf solid 1px;text-align: center;">
                                    <input type="checkbox" class="Bef-obj-id" id="{{ Bef.id }}" value="{{ Bef.reception_reason }}">
                                </td>
                                <td style="width: 8%;height: 35px;border: #cfcfcf solid 1px;text-align: center;">{{ forloop.counter }}</td>
                                <td style="width: 87%;height: 35px;border: #cfcfcf solid 1px;padding-left: 0.5%;">{{ Bef.reception_reason }}</td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
                <div id="reception_list" style="width: 100%;height: 405px;overflow: auto;border-bottom: #cfcfcf solid 1px;vertical-align: top;display: none;">
                    <table style="width: 100%;margin: 0;padding: 0;border-collapse: collapse;">
                        <tr style="width: 100%;">
                            <th style="width: 5%;height: 35px;border: #cfcfcf solid 1px;text-align: center;border-top: none;"></th>
                            <th style="width: 8%;height: 35px;border: #cfcfcf solid 1px;text-align: center;border-top: none;">序号</th>
                            <th style="width: 87%;height: 35px;border: #cfcfcf solid 1px;text-align: center;border-top: none;">申请事由</th>
                        </tr>
                        {% for Bec in ReceptionObj %}
                            <tr style="width: 100%;">
                                <td style="width: 5%;height: 35px;border: #cfcfcf solid 1px;text-align: center;">
                                    <input type="checkbox" class="Bec-obj-id" id="{{ Bec.id }}" value="{{ Bec.official_interaction }}">
                                </td>
                                <td style="width: 8%;height: 35px;border: #cfcfcf solid 1px;text-align: center;">{{ forloop.counter }}</td>
                                <td style="width: 87%;height: 35px;border: #cfcfcf solid 1px;padding-left: 0.5%;">{{ Bec.official_interaction }}</td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
                <div style="width: 100%;height: 45px;text-align: right;padding-right: 30px;">
                    <button onclick="close_association()" style="width: 100px;height: 30px;margin-top: 9px;border: #cfcfcf solid 1px;background: #cfcfcf;border-radius: 3px;">取消</button>
                    <button onclick="ConfirmAssociation()" style="width: 100px;height: 30px;margin-top: 9px;border: #2db7f5 solid 1px;background: #2db7f5;color: white;border-radius: 3px;margin-left: 15px;">确认</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
{#    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>#}
{#    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->#}
    <script src="../../static/system_setup/creat_from/js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="../../static/public_file/js/DepartmentSelection.js"></script>
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("personage").className = "add_class";
            document.getElementById("sponsor").className = "add-nav-active";
        };
        const uuid = "{{ uuid | safe }}"
        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid)
            form.append('source', 'fklc')     // 总务科付款
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function ExportCar() {
            var BgsFalse = '{{ bgs_flag | safe }}';
            var total_money = document.getElementById('total_money').value;                       // 总金额
            var daxie = document.getElementById('daxie').innerText;                               // 总金额大写
            var rask = document.getElementById('rask').innerText;                                   // 备注
            var payee = document.getElementById('payee').innerText;                                 // 收款单位
            var payee_account = document.getElementById('payee_account').innerText;                 // 收款账号
            var SourceFunds = document.getElementById('source_funds').value;                   // 经费来源
            var pay_reason = document.getElementById('pay_reason').innerText;                       // 付款事由
            var BankDeposit = document.getElementById('BankDeposit').innerText;                       // 开户行
            var pay_type_select = document.getElementById('pay_type_select').value;                       // 付款类型
            var fenguan_leader = '';var demand_office = '';
            var PreReceptionId = $("#PreReception").attr("data-value");
            var ReceptionChecklistId = $("#ReceptionChecklist").attr("data-value");
            var expense_category = "";
            if (parseInt(total_money.replace(",", '').replace(",", '').replace(',', '')) >= 10000) {
                alert("一万元以上该流程无法申请！");
                return false
            }

            var administrative_table = document.getElementById('party_main');
            if (!administrative_table.children.length) {
                alert("请上传附件！");
                return false
             }

            if (!BankDeposit){
                alert("请填写开户行！");
                return false
            }
            if (!payee) {
                alert("请填写收款单位！");
                return false
            }
            if (!payee_account) {
                alert("请填写收款账号！");
                return false
            }

            if (pay_type_select === "0") {
                alert("请选择付款类型！");
                return false
            }

            if (SourceFunds === '0') {
                alert("请选择经费来源！");
                return false
            }

            if (BgsFalse === 'true') {
                fenguan_leader = document.getElementById("fenguan_leader").value;
                demand_office = document.getElementById("demand_office").innerText;
            }

            if (pay_type_select === "5") {
                expense_category = document.getElementById("expense_category").value;
                if (expense_category === '0') {
                    alert("请选择费用类别！");
                    return false
                }
            }

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/payment_process_index.html", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("total_money=" + total_money + "&daxie="+ String(daxie)+"&rask="+rask+"&fj_number="+String(uuid)+"&payee_account="+payee_account+"&pay_reason="+pay_reason+"&payee="+String(payee)+"&source_funds="+String(SourceFunds)+"&BankDeposit="+BankDeposit+"&pay_type_select="+pay_type_select+"&fenguan_leader="+fenguan_leader+"&demand_office="+String(demand_office)+"&PreReceptionId="+String(PreReceptionId)+"&ReceptionChecklistId="+String(ReceptionChecklistId)+"&expense_category="+String(expense_category));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert(JsonDate["message"])
                            window.location.href = "/finance/payment_process_list.html"
                        } else {
                            alert(JsonDate["message"])
                        }
                    }
                }
            };
        }

        function ToString(money) {
            console.log(money, '执行了吗');
            //汉字的数字
            var cnNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
            //基本单位
            var cnIntRadice =['', '拾', '佰', '仟'];
            //对应整数部分扩展单位
            var cnIntUnits = ['', '万', '亿', '兆'];
            //对应小数部分单位
            var cnDecUnits = ['角', '分', '毫', '厘'];
            //整数金额时后面跟的字符
            var cnInteger = '整';
            //整型完以后的单位
            // var cnIntLast = '圆';
            var cnIntLast = '元';
            //最大处理的数字
            var maxNum = 999999999999999.9999;
            //金额整数部分
            var integerNum;
            //金额小数部分
            var decimalNum;
            //输出的中文金额字符串
            var chineseStr = '';
            //分离金额后用的数组，预定义
            var parts;
            if (money === '') { return ''; }
            money = parseFloat(money);
            if (money >= maxNum) {
                //超出最大处理数字
                return '';
            }
            if (money === 0) {
                chineseStr = cnNums[0] + cnIntLast + cnInteger;

                return chineseStr;
            }

            //转换为字符串
            money = money.toString();

            if (money.indexOf('.') === -1) {
                integerNum = money;
                decimalNum = '';
            } else {
                parts = money.split('.');
                integerNum = parts[0];

                decimalNum = parts[1].substring(0, 2);
            }
            //获取整型部分转换
            if (parseInt(integerNum, 10) > 0) {
                var zeroCount = 0;
                var IntLen = integerNum.length;
                for (var i = 0; i < IntLen; i++) {
                    // var n = integerNum.substr(i, 1);
                    var n = integerNum.substring(i, i+1);
                    var p = IntLen - i - 1;
                    var q = p / 4;
                    var m = p % 4;
                    if (n === '0') {
                        zeroCount++;
                    } else {
                        if (zeroCount > 0) {
                            chineseStr += cnNums[0];
                        }
                        //归零
                        zeroCount = 0;
                        chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
                    }
                    if (m === 0 && zeroCount < 4) {
                        chineseStr += cnIntUnits[q];
                    }
                }
                chineseStr += cnIntLast;
            }
            //小数部分
            if (decimalNum !== '') {
                var decLen = decimalNum.length;
                for (var i = 0; i < decLen; i++) {
                    // var n = decimalNum.substr(i, 1);
                    var n = decimalNum.substring(i, i+1);
                    if (n !== '0') {
                        // chineseStr += cnNums[Number(n)] + cnDecUnits[i];
                        chineseStr += cnNums[parseInt(n)] + cnDecUnits[i];
                    }
                }
            }
            if (chineseStr === '') {
                chineseStr += cnNums[0] + cnIntLast + cnInteger;
            } else if (decimalNum === '') {
                chineseStr += cnInteger;
            }

            return chineseStr;
        }

        function change_daxie() {
            document.getElementById("daxie").innerText=ToString(document.getElementById("total_money").value.replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', ''));
            document.getElementById("total_money").value = formatMonenyNumber(document.getElementById("total_money").value.replace(',', '').replace(',', '').replace(',', '').replace(',', '').replace(',', ''));
        }

        function formatMonenyNumber(number, toFixed = 2) {
            let str = [];
            if (!number) return 0
            if (typeof number === "number") number = String(number)
            let tempNumber = number.split('.');
            number = tempNumber[0]
            if (number.length <= 3) {
                if (tempNumber[1]) {
                    var decimils = tempNumber[1].slice(0, toFixed);
                if (decimils.length === 1){
                    decimils = decimils + "0";
                }
                number += '.' + decimils;
                }else {
                    number += '.00'
                }
                return number
            }
            number.split('').reverse().forEach((item, index) => {
                if (index !== 0 && index % 3 === 0) {
                    str.push(',', item)
                } else {
                    str.push(item)
                }
            })
            number = str.reverse().join('')
            if (tempNumber[1]) {
                var decimils = tempNumber[1].slice(0, toFixed);
                if (decimils.length === 1){
                    decimils = decimils + "0";
                }
                number += '.' + decimils;
            }else {
                 number += '.00'
            }
            return number;
        }

        function summit_val() {
            var processed_prople = document.getElementsByClassName("selected-department");
            if (processed_prople.length === 0){
                alert("请选择拟稿科室！");
                return false
             }
            var dep_list=[];
            for (var i=0; i<processed_prople.length; i++) {
                dep_list.push(processed_prople[i].innerText)
            }
            document.getElementById("demand_office").innerText=dep_list.join();
            close_office_models();
        }

        function search_dep() {
            var company_list = {{ company_list | safe }};
            var search_keyword = document.getElementById("search_data1").value;
            var processed = document.getElementById("processed");
            processed.innerHTML = "";
            for (var h=0; h<company_list.length; h++){
                if (company_list[h]["name"].indexOf(search_keyword) !== -1){
                    console.log(company_list[h]["name"])
                    var div_tag = document.createElement("div");div_tag.className="div_clase";
                    div_tag.innerHTML = '<input class="check_box1" id="'+company_list[h]["id"]+'" type="checkbox" onclick="check_dep_ff(\''+company_list[h]["name"]+'\', \''+company_list[h]["id"]+'\', false)"> '+ company_list[h]["name"];
                    processed.appendChild(div_tag)
                }
            }
        }

        let association_title = document.querySelector("#association-title");
        let association_model = document.querySelector("#association-model");

        association_title.addEventListener("mousedown", function (e) {
            let x = e.pageX - association_model.offsetLeft;
            let y = e.pageY - association_model.offsetTop;
            document.addEventListener("mousemove", move);

            function move(e) {
                association_model.style.left = e.pageX - x + 'px';
                association_model.style.top = e.pageY - y + 'px';
            }

            document.addEventListener("mouseup", function (e) {
                document.removeEventListener("mousemove", move);
            })
        });

        function association_line(label_id) {
            if (label_id === 'PreReception') {
                document.getElementById("SwitchOne").style.display = "block";
                document.getElementById("SwitchTwo").style.display = "none";
                document.getElementById("approval_reception").style.display = "block";
                document.getElementById("reception_list").style.display = "none";
            }else {
                document.getElementById("SwitchOne").style.display = "none";
                document.getElementById("SwitchTwo").style.display = "block";
                document.getElementById("reception_list").style.display = "block";
                document.getElementById("approval_reception").style.display = "none";
            }
            document.getElementById("association").style.display = "table-row";
        }

        function close_association() {
            document.getElementById("association").style.display = "none";
        }

        function ConfirmAssociation() {
            var SwitchOneStyle = document.getElementById("SwitchOne").style.display;
            var SwitchTwoStyle = document.getElementById("SwitchTwo").style.display;
            if (SwitchOneStyle === 'block') {
                var bef_obj_list = document.getElementsByClassName("Bef-obj-id");
                for (var i=0; i<bef_obj_list.length; i++) {
                    if (bef_obj_list[i].checked) {
                        var bef_text = bef_obj_list[i].value;
                        var bef_id = bef_obj_list[i].id;
                        document.getElementById("PreReception").setAttribute("data-value", bef_id)
                        document.getElementById("PreReception").innerText = "";
                        $("#PreReception").append(`<a href="/new-flow-logic/official_business_reception_detail.html?id=`+bef_id+`">`+bef_text+`</a>`)
                        close_association();
                        return
                    }
                }
            }
            if (SwitchTwoStyle === 'block') {
                var bec_obj_list = document.getElementsByClassName("Bec-obj-id");
                for (var j=0; j<bec_obj_list.length; j++) {
                    if (bec_obj_list[j].checked) {
                        var bec_text = bec_obj_list[j].value;
                        var bec_id = bec_obj_list[j].id;
                        document.getElementById("ReceptionChecklist").setAttribute("data-value", bec_id)
                        document.getElementById("ReceptionChecklist").innerText = "";
                        $("#ReceptionChecklist").append(`<a href="/new-flow-logic/reception_checklist_detail.html?id=`+bec_id+`">`+bec_text+`</a>`)
                        close_association();
                        return
                    }
                }
            }
        }

        function change_pay_type() {
            var pay_type_val = document.getElementById("pay_type_select").value;
            if (pay_type_val === '5') {
                document.getElementById("expense_category_tr").style.display = "table-row";
            }else {
                document.getElementById("expense_category_tr").style.display = "none";
            }
        }
    </script>
{% endblock %}
